home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / COSEmulator / COSEmulator- SRC / src / ApplicationHandler.cpp < prev    next >
Encoding:
Text File  |  1998-06-21  |  7.2 KB  |  319 lines  |  [TEXT/CWIE]

  1. //===================================================================
  2. //=======================  Headers        =============================
  3.  
  4. #include "ApplicationHandler.h"
  5. #include "ApplicationEvents.h"
  6. #include "MenuBar.h"
  7. #include "Screen.h"
  8.  
  9. #include "BogusFinder.h"
  10. #include "BogusPhotoshop.h"
  11. #include "MacAmp.h"
  12. #include "BogusQuickTime.h"
  13.  
  14. //===================================================================
  15. //=======================  Globals        =============================
  16.  
  17. ApplicationHandler    AH;
  18.  
  19. //===================================================================
  20. //=======================  #define        =============================
  21.  
  22.  
  23. //===================================================================
  24. //=======================  Function Prototypes    =====================
  25.  
  26. /*----------------------------------------------------------------------------\
  27.  
  28.     ApplicationHandler :: Constructor
  29.  
  30. \----------------------------------------------------------------------------*/
  31. void    ApplicationHandlerInit( void )
  32. {
  33.     AH.LoadApplication( kFinderApp );
  34. }
  35.  
  36. /*----------------------------------------------------------------------------\
  37.  
  38.     ApplicationHandler :: Constructor
  39.  
  40. \----------------------------------------------------------------------------*/
  41.     ApplicationHandler :: ApplicationHandler( void )
  42.                         : LinkListClass< Application >()
  43. {
  44.     multApps = false;
  45.     finder     = NULL;
  46.     action = 0;
  47. }
  48.  
  49. /*----------------------------------------------------------------------------\
  50.  
  51.     ApplicationHandler :: HandleMouseClick
  52.  
  53. \----------------------------------------------------------------------------*/
  54. void    ApplicationHandler :: HandleMouseClick( Boolean down, point where )
  55. {
  56.     if( LastLink != NULL )
  57.     {
  58.         if( LastLink == finder )
  59.         {
  60.             finder->HandleMouseClick( down , where );
  61.         }
  62.         else if( !down )
  63.         {
  64.             LastLink->HandleMouseClick( down , where );
  65.         }
  66.         else
  67.         if( !LastLink->HandleMouseClick( down , where ) )
  68.         {
  69.         // ifthe front app does not hadnle it go through the app
  70.         // list untill something is hit
  71.             Application    *link = FirstLink;
  72.             
  73.             if( link == LastLink )
  74.                 link = link->next;
  75.             
  76.             while( link != NULL )
  77.             {
  78.                 if( link->HandleMouseClick( down , where ) )
  79.                 {                
  80.                     MakeFrontApp( link );
  81.                     return;
  82.                 }
  83.                 
  84.                 link = link->next;
  85.                 
  86.                 if( link == LastLink )
  87.                     link = NULL;
  88.             }        
  89.         // nothing hit then go to the bogus finder
  90.             
  91.             if( down )
  92.             {
  93.                 action |= 0x02;
  94.                 whichSwitch = finder;
  95.             }
  96.         }
  97.     }
  98. }
  99.  
  100. /*----------------------------------------------------------------------------\
  101.  
  102.     ApplicationHandler :: HandleMouseMove
  103.  
  104. \----------------------------------------------------------------------------*/
  105. void    ApplicationHandler :: HandleMouseMove( point where )
  106. {
  107.     if( LastLink == finder )
  108.     {
  109.         finder->HandleMouseMove( where );
  110.     }
  111.     else
  112.         LastLink->HandleMouseMove( where );
  113. }
  114.  
  115. /*----------------------------------------------------------------------------\
  116.  
  117.     ApplicationHandler :: CleanUp
  118.  
  119. \----------------------------------------------------------------------------*/
  120. void    ApplicationHandler :: CleanUp( rect *where )
  121. {
  122.     Application    *link = FirstLink;
  123.     
  124.     if( finder != NULL && LastLink != finder )
  125.     {
  126.         finder->CleanUp( where );
  127.         
  128.         if( link == finder )
  129.             link = link->next;    
  130.     }
  131.         
  132.     while( link != NULL )
  133.     {
  134.         link->CleanUp( where );
  135.         
  136.         link = link->next;
  137.  
  138.         if( link == finder )
  139.             link = link->next;
  140.     }    
  141.     
  142.     if( LastLink == finder )
  143.     {
  144.         finder->CleanUp( where );
  145.     }
  146. }
  147.  
  148. /*----------------------------------------------------------------------------\
  149.  
  150.     ApplicationHandler :: Maintance
  151.  
  152. \----------------------------------------------------------------------------*/
  153. void    ApplicationHandler :: Maintance( void )
  154. {
  155. // see if it needs to switch apps
  156.     if( action & 0x01)
  157.         RealLoadApp( whichLoad );
  158.     
  159.     if( action & 0x02 )
  160.         MakeFrontApp( whichSwitch );
  161.     
  162.     action = 0;
  163.     
  164. //    do app maintance
  165.  
  166.     Application    *link = FirstLink;
  167.     
  168.     while( link != NULL )
  169.     {
  170.         link->Maintance();
  171.         link = link->next;
  172.     }
  173.     
  174.     
  175. }
  176.  
  177. /*----------------------------------------------------------------------------\
  178.  
  179.     ApplicationHandler :: LoadApplication
  180.  
  181. \----------------------------------------------------------------------------*/
  182. void    ApplicationHandler :: LoadApplication( uchar what )
  183. {    
  184.     action |= 0x01;
  185.     whichLoad = what;
  186. }
  187.  
  188. /*----------------------------------------------------------------------------\
  189.  
  190.     ApplicationHandler :: RealLoadApp
  191.  
  192. \----------------------------------------------------------------------------*/
  193. void    ApplicationHandler :: RealLoadApp( uchar what )
  194. {    
  195.     Application    *link;
  196.     
  197.     link = NewApp( what );
  198.     AddToList( link );
  199.  
  200.     MakeFrontApp( link );
  201. }
  202.  
  203. /*----------------------------------------------------------------------------\
  204.  
  205.     ApplicationHandler :: LoadMultipleApps
  206.  
  207. \----------------------------------------------------------------------------*/
  208. Boolean    ApplicationHandler :: LoadMultipleApps( Boolean what )
  209. {
  210.     multApps = what;
  211. }
  212.  
  213. /*----------------------------------------------------------------------------\
  214.  
  215.     ApplicationHandler :: SendEventToCurrentApp
  216.  
  217. \----------------------------------------------------------------------------*/
  218. void    ApplicationHandler :: SendEventToCurrentApp( ushort event , void *data )
  219. {
  220. // if it is a menu select intersept it and see if it should be sent
  221. // to the menu bar
  222.     if( event == kAEMenuSelect )
  223.     {
  224.         if( ((AEMenuWhere *)data)->which == kAppleMenuTitle ||
  225.             ((AEMenuWhere *)data)->which == kAppListMenuTitle )
  226.         {
  227.             menuBar.HandleSpecialMenuSelect( ((AEMenuWhere *)data)->which ,
  228.                                              ((AEMenuWhere *)data)->num );
  229.             return;
  230.         }
  231.     }
  232.     LastLink->HandleEvent( event , data );
  233. }
  234.  
  235. /*----------------------------------------------------------------------------\
  236.  
  237.     ApplicationHandler :: NewApp
  238.  
  239. \----------------------------------------------------------------------------*/
  240. Application    *ApplicationHandler :: NewApp( uchar what )
  241. {
  242.     Application    *temp = NULL;
  243.     
  244.     switch( what )
  245.     {
  246.     case kFinderApp:
  247.         temp = new BogusFinder;
  248.         ((BogusFinder *)temp)->Init();
  249.         
  250.         finder = temp;
  251.     break;
  252.     
  253.     case kPhotoshopApp:
  254.         temp = new BogusPhotoshop;
  255.         ((BogusPhotoshop *)temp)->Init();
  256.     break;
  257.     
  258.     case kMacAmp:
  259.         temp = new MacAmp;
  260.         ((MacAmp *)temp)->Init();
  261.     break;
  262.     
  263.     case kQuickTime:
  264.         temp = new BogusQuickTime;
  265.         ((BogusQuickTime *)temp)->Init();
  266.     break;
  267.     }
  268.     
  269.     return temp;
  270. }
  271.  
  272. /*----------------------------------------------------------------------------\
  273.  
  274.     ApplicationHandler :: MakeFrontApp
  275.  
  276. \----------------------------------------------------------------------------*/
  277. void    ApplicationHandler :: MakeFrontApp( Application *app )
  278. {
  279.     if( LastLink != NULL )
  280.         LastLink->HandleEvent( kAEGoBackGroundEvent , NULL );
  281.             
  282.     menuBar.ClearMenuList();
  283.     
  284.     app->HandleEvent( kAEMakeFrontAppEvent , NULL );
  285.     
  286.     MoveAfter( LastLink , app );
  287.     
  288.     screen.DrawAll();
  289.     
  290.     Application    *temp;
  291.     
  292.     for( temp = LastLink ; temp != NULL ; temp = temp->previous ) 
  293.         menuBar.AddAppToList( temp->GetAppType() ); 
  294. }
  295.  
  296. /*----------------------------------------------------------------------------\
  297.  
  298.     ApplicationHandler :: MakeFrontApp
  299.  
  300. \----------------------------------------------------------------------------*/
  301. void    ApplicationHandler :: SwitchToAppByNum( uchar num )
  302. {
  303.     Application    *temp;
  304.     uchar        i = 0;
  305.     
  306.     for( temp = LastLink ; temp != NULL ; temp = temp->previous ) 
  307.     {
  308.         if( num == i )
  309.         {
  310.             if( temp == LastLink )
  311.                 return;
  312.                 
  313.             action |= 0x02;
  314.             whichSwitch = temp;
  315.             return;
  316.         }
  317.         i++;
  318.     }
  319. }